package com.pignest.hotel.service;

import java.util.List;

import com.pignest.hotel.beans.Role;
import com.pignest.hotel.beans.User;
import com.pignest.hotel.dao.RoleDao;

public class RoleService extends BaseService {
	
	private RoleDao roleDao;

	public void addUserRole(User user, Role role) {
		roleDao.addUserRole(user, role);
	}

	public void addUserRoles(User user, List<String> roleIds) {
		roleDao.addUserRoles(user, roleIds);
	}

	public void addUserRoles(String[] userIds, Role role) {
		roleDao.addUserRoles(userIds, role);
	}

	public void clearUserRoles(User user) {
		roleDao.clearUserRoles(user);
	}

	public void clearUserRoles(Role role) {
		roleDao.clearUserRoles(role);
	}

	public void deleteUserRoles(String[] ids) {
		roleDao.deleteUserRoles(ids);
	}

	public Role getRoleByName(String roleName) {
		return roleDao.getRoleByName(roleName);
	}
	
	public void deleteRole(Role role) {
		clearUserRoles(role);
		delete(role);
	}

	public List<Role> getRolesByUser(User user) {
		return roleDao.getRolesByUser(user);
	}

	public List<User> getUsersByRole(Role role) {
		return roleDao.getUsersByRole(role);
	}

	public void removeUserFromRole(Role role, String[] userIds) {
		roleDao.removeUserFromRole(role, userIds);
	}
	
	public void saveUserRole(User user, List<String> roleIds) {
		roleDao.clearUserRoles(user);
		roleDao.addUserRoles(user, roleIds);
	}
	
	/////////////////////////////////////////////////////////////////////////

	public void setRoleDao(RoleDao roleDao) {
		this.roleDao = roleDao;
	}
}
